<template>
  <div>
    <el-form :model="addData" ref="addform" label-width="100px" size="small">
      <el-form-item label="充值金额">
        <el-input v-model="addData.money" placeholder="请输入" style="width: 80%"/>
      </el-form-item>
      <el-form-item label="到账金额">
        <el-input v-model="addData.remain_money" placeholder="请输入" style="width: 80%"/>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="addData.remarks" type="textarea" placeholder="请输入" style="width: 80%"/>
      </el-form-item>
      <el-form-item label="状态">
        <el-switch v-model="addData.status" active-color="#13ce66" active-value="1" inactive-value="0"></el-switch>
      </el-form-item>
    </el-form>

    <div style="text-align:center">
      <el-button type="primary" size="small" style="padding:8px 30px;" @click="submit">提 交</el-button>
    </div>
  </div>
</template>

<script>
import { postPay, putPay } from '@/api/marketing'

export default {
  props: {
    addData: {
      type: Object,
      required: true
    },
    isAdd: {
      type: Boolean,
      required: true
    }
  },
  methods: {
    /**
     * 提交
     */
    submit() {
      this.$refs.addform.validate((valid) => {
        if(valid) {
          if(this.isAdd){
            postPay(this.addData).then(response => {
              if(response.status === 200){
                this.$emit('success');
                this.$message.success('添加成功！');
              }else{
                this.$message.error(response.message);
              }
            })
          }else{
            putPay(this.addData).then(response => {
              if(response.status === 200){
                this.$emit('success');
                this.$message.success('修改成功！');
              }else{
                this.$message.error(response.message);
              }
            })
          }
        }
      })    
    },
  },
}
</script>